<?
/*
Plugin Name: Format Comments 
Plugin URI: http://tantannoodles.com/
Description: Inserts whitespace every X characters, preserves HTML tags
Version: 0.1
Author: Joe Tan
Author URI: http://tantannoodles.com/about/
*/

function tantan_formatComments($comment = '') {
    return tantan_htmlwrap($comment, '60', ' ');
}

function tantan_htmlwrap($str,$cols,$cut) {  
    $len=strlen($str);   
    $tag=0;  
    for ($i=0;$i<$len;$i++) {   
        $chr = substr($str,$i,1);   
        if ($chr=="<") $tag++;   
        elseif ($chr==">") $tag--;   
        elseif (!$tag && $chr==" ") $wordlen=0;   
        elseif (!$tag) $wordlen++;   
        
        if (!$tag && !($wordlen%$cols)) $chr .= $cut;     
        $result .= $chr;  
    }    
    return $result; 
}

add_filter('comment_text', 'tantan_formatComments');

?>